#define  _CRT_SECURE_NO_WARNINGS
#include "date.h"

//bool CheckDate(int year, int month, int day)
//{
//
//}

bool date::operator<(const date& d)
{
	if (this->_year < d._year)
	{
		return true;
	}
	else if (this->_month < d._month)
	{
		return true;
	}
	else if (this->_day < d._day)
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool date::operator==(const date& d)
{
	if (this->_year == d._year && this->_month == d._month && this->_day == d._day)
	{
		return true;
	}
	else
	{
		return false;
	}
}
bool date::operator!=(const date& d)
{
	return !operator==(d);
}


bool date::operator>=(const date& d)
{
	return !date::operator<(d) || date::operator==(d);
}

date& date::operator+=(int day)
{
	int days = _day + day;
	while (days > GetMonthDay())
	{
		days -= GetMonthDay();
		_month++;
		if (_month > 12)
		{
			_year++ ;
			_month = 1;
		}
	}
	_day = days;
	return *this;
}

date date::operator+(int day)
{
	date tmp = *this;
	tmp += day;
	return tmp;
}

date& date::operator-=(int day)
{
	int days = _day - day;
	while (days <= 0)
	{
		_month--;
		if (_month < 1)
		{
			_year--;
			_month = 12;
		}
		days += GetMonthDay();
	}
	_day = days;
	return *this;
}

date date::operator-(int day)
{
	date tmp = *this;
	tmp -= day;
	return tmp;
}

int date::operator-(const date& d)
{
	date max = *this;
	date min = d;
	if (*this >= d)
	{
		max = d;
		min = *this;
	}
	int days = 0;
	while (min != max)
	{
		min += 1;
		days++;
	}
	return days;
}
